import 'package:flutter/material.dart';
import 'package:flutter_app/components/layout.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:flutter_app/generated/l10n.dart';
class DoubleBuyPage extends StatefulWidget {
  @override
  _DoubleBuyPageState createState() => _DoubleBuyPageState();
}

class _DoubleBuyPageState extends State<DoubleBuyPage> {
  bool isAgree = false;
  void showCoupon() {
    GetBottomSheet(context, text: '选择优惠券', children: [
      Wrap(
        children: [
          Container(
            decoration: BoxDecoration(color: Colors.white),
            child: ColumnStart(children: [
              Text('BTC双币：满0.01BTC可用'),
              Text('BTC-U双币：满100 USDC/USDT 可用'),
              Text('ETH双币：满0.1ETH可用'),
              Text('ETH-U双币：满100 USDC/USDT 可用'),
              Text('BCH双币：满0.1BCH可用'),
              Text('BCH-U双币：满100USDC/USDT可用'),
              Text('适用于期限≤7天的产品'),
            ]),
          )
        ],
      ),
      FlatButton(
          color: Colors.blueAccent,
          textColor: Colors.white,
          onPressed: () {},
          //confirm 确认
          child: Text(S.of(context).confirm))
    ]);
  }

  void showCharge() {
    GetBottomSheet(
      context,
      text: '充币BTC',
      children: [
        SizedBox(height: 20),
        Container(
          padding: EdgeInsets.all(19.0),
          decoration: BoxDecoration(
            image: DecorationImage(
              // alignment: Alignment(0.9, 0.5),
              image: AssetImage("assets/images/bg_qrcode_frame.png"),
              fit: BoxFit.contain,
            ),
          ),
          child: QrImage(
            //二维码设置前后背景色，不设置的情况下保存图片后因为是png格式的，白色透明的地方都是黑色的，导致查看图片时就是一个黑图
            foregroundColor: Colors.black, //前景色
            backgroundColor: Colors.white, //背景色
            data: "123333",
            size: 160,
          ),
        ),
        SizedBox(height: 20),
        Container(
          margin: EdgeInsets.only(right: 15.0),
          alignment: Alignment.center,
          padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 15.0),
          decoration: BoxDecoration(
            color: Colors.grey.withOpacity(0.07),
            borderRadius: BorderRadius.circular(100),
          ),
          child: Text(
            '0XSHI908888...XHSAKSH7782BHSAHI9088',
            style: TextStyle(color: Colors.black45),
          ),
        ),
        SizedBox(height: 20),
        Container(
          height: 45,
          width: 200,
          child: FlatButton(
              color: Colors.blueAccent,
              textColor: Colors.white,
              onPressed: () {},
              child: Text('复制地址')),
        ),
        SizedBox(height: 20),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: DarkHeadBar('购买'),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 15.0),
        child: ColumnStart(children: [
          Expanded(
              child: ColumnStart(children: [
            Stack(
              children: [
                TextField(
                  decoration: InputDecoration(
                      hintText: "最小起投：0.1",
                      contentPadding: EdgeInsets.only(right: 200)),
                ),
                Positioned(
                    right: 0,
                    child: Row(
                      children: [
                        TextButton(
                          child: Text(
                            'Max',
                            style: TextStyle(
                                color: Colors.blueAccent,
                                fontSize: 16,
                                fontWeight: FontWeight.w500),
                          ),
                        ),
                        VerticalDivideLine(),
                        SizedBox(width: 16),
                        GestureDetector(
                          // onTap: () => showSelectCoin(),
                          child: Row(children: [
                            Image.asset(
                              'assets/images/ic_btc.png',
                              width: 25,
                              height: 25,
                            ),
                            SizedBox(width: 6.0),
                            Text('BTC',
                                style: TextStyle(
                                    fontWeight: FontWeight.w600, fontSize: 16)),
                          ]),
                        )
                      ],
                    ))
              ],
            ),
            Row(
              children: [
                Text(
                  '账户余额：0 ETH',
                  style: TextStyle(fontSize: 15),
                ),
                TextButton(onPressed: showCharge, child: Text('充币'))
              ],
            ),
            SizedBox(height: 15),
            GestureDetector(
              onTap: showCoupon,
              child: RowBetween(
                children: [
                  Expanded(
                      child: Text(
                    '优惠券',
                    style: TextStyle(fontWeight: FontWeight.w500, fontSize: 16),
                  )),
                  Icon(
                    Icons.arrow_forward_ios_rounded,
                    size: 13,
                  )
                ],
              ),
            )
          ])),
          //  bottom
          ColumnStart(
            children: [
              Row(
                children: [
                  SizedBox(
                    height: 24.0,
                    width: 24.0,
                    child: Checkbox(
                      value: isAgree,
                      onChanged: (bool value) {
                        setState(() {
                          this.isAgree = value;
                        });
                      },
                    ),
                  ),
                  SizedBox(width: 5),
                  Text('我已阅读且同意'),
                  TextButton(
                    onPressed: () {
                      Navigator.pushNamed(context, '/agreement');
                    },
                    child: Text(
                      '投资协议',
                      style: TextStyle(color: Colors.blueAccent),
                    ),
                  )
                ],
              ),
              SizedBox(
                height: 20,
              ),
              Container(
                  color: Colors.blueAccent,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      FlatButton(
                          onPressed: () {},
                          textColor: Colors.white,
                          child: Text('确认购买')),
                    ],
                  ))
            ],
          )
        ]),
      ),
    );
  }
}
